package com.puti.doctor.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.Page;
import com.puti.common.core.domain.R;
import com.puti.common.redis.service.RedisService;
import com.puti.doctor.domain.HospitalDoctorInfo;
import com.puti.doctor.domain.util.RandomNumUtil;
import com.puti.doctor.domain.vo.DoctorPatientVo;
import com.puti.doctor.domain.vo.DoctorRecordVo;
import com.puti.doctor.domain.vo.PatientRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;
import com.puti.doctor.domain.DoctorPatientRecord;
import com.puti.doctor.service.IDoctorPatientRecordService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 医生-患者-记录 医生-患者-记录Controller
 * 
 * @author puti
 * @date 2021-04-22
 */
@CrossOrigin
@RestController
@RequestMapping("/record")
public class DoctorPatientRecordController extends BaseController
{
    @Autowired
    private IDoctorPatientRecordService doctorPatientRecordService;

    /**
     * 查询医生-患者-记录 医生-患者-记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DoctorPatientRecord doctorPatientRecord)
    {
        startPage();
        List<DoctorPatientRecord> list = doctorPatientRecordService.selectDoctorPatientRecordList(doctorPatientRecord);
        return getDataTable(list);
    }

    /**
     * 导出医生-患者-记录 医生-患者-记录列表
     */
    @Log(title = "医生-患者-记录 医生-患者-记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorPatientRecord doctorPatientRecord) throws IOException
    {
        List<DoctorPatientRecord> list = doctorPatientRecordService.selectDoctorPatientRecordList(doctorPatientRecord);
        ExcelUtil<DoctorPatientRecord> util = new ExcelUtil<DoctorPatientRecord>(DoctorPatientRecord.class);
        util.exportExcel(response, list, "医生-患者-记录 医生-患者-记录数据");
    }

    /**
     * 获取医生-患者-记录 医生-患者-记录详细信息
     */
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(doctorPatientRecordService.selectDoctorPatientRecordById(recordId));
    }

    /**
     * 新增医生-患者-记录 医生-患者-记录
     */
    @Log(title = "医生-患者-记录 医生-患者-记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorPatientRecord doctorPatientRecord)
    {
        return toAjax(doctorPatientRecordService.insertDoctorPatientRecord(doctorPatientRecord));
    }

    /**
     * 修改医生-患者-记录 医生-患者-记录
     */
    @Log(title = "医生-患者-记录 医生-患者-记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorPatientRecord doctorPatientRecord)
    {
        return toAjax(doctorPatientRecordService.updateDoctorPatientRecord(doctorPatientRecord));
    }

    /**
     * 删除医生-患者-记录 医生-患者-记录
     */
    @Log(title = "医生-患者-记录 医生-患者-记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(doctorPatientRecordService.deleteDoctorPatientRecordByIds(recordIds));
    }
    //接诊台-已接诊列表-按时间正序排列；
    @GetMapping("/patients/{recordDoctorId}")
    public R selectRecordList(@PathVariable("recordDoctorId") Long recordDoctorId,int page,int pageSize){
        Page doctorPatientVos = doctorPatientRecordService.selectRecordList(recordDoctorId,page,pageSize);
        if(doctorPatientVos!=null){
            return R.ok(doctorPatientVos,"查询成功");
        }else{
            return R.fail("查询失败");
        }
    }
    //接诊台-未接诊列表-按时间正序排列；
    @GetMapping("/patientz/{recordDoctorId}")
    public R selectRecord(@PathVariable("recordDoctorId") Long recordDoctorId,int page,int pageSize) {
        Page doctorPatientRecords = doctorPatientRecordService.selectRecord(recordDoctorId,page,pageSize);
        if(doctorPatientRecords!=null){
            return R.ok(doctorPatientRecords,"查询成功!");
        }else{
            return R.fail("查询失败");
        }
    }
    //诊断管理-列表展示-按时间倒序排列：
    @GetMapping("/doctor/{recordDoctorId}")
    public R findByDoctor(@PathVariable("recordDoctorId") Long recordDoctorId,String patientName,String startTime,String endTime,int page,int pageSize) {
        Page recordVos = doctorPatientRecordService.findByDoctor(recordDoctorId,patientName,startTime,endTime,page,pageSize);
        if(recordVos!=null){
            return R.ok(recordVos,"查询成功!");
        }else{
            return R.fail("查询失败!");
        }
    }
    //诊断管理-查看患者列表-按时间倒序排列；
    @GetMapping("/findPatentDoctorId/{recordDoctorId}")
    public R findPatentDoctorId(@PathVariable("recordDoctorId") Long recordDoctorId,
                                @RequestParam(value = "dateTime")String dateTime,int page,int pageSize){
        Page patentDoctorId = doctorPatientRecordService.findPatentDoctorId(recordDoctorId,dateTime,page,pageSize);
        if(patentDoctorId!=null){
            return R.ok(patentDoctorId,"查询成功");
        }else{
            return R.fail("没有数据!!!!");
        }
    }

}
